Skip to content

refactor: deduplicate net/discount calculation in line item strategies#17

Merged
inflop merged 2 commits into
masterfrom
chore/pre-release-audit
Apr 28, 2026
Merged

refactor: deduplicate net/discount calculation in line item strategies#17
inflop merged 2 commits into
masterfrom
chore/pre-release-audit

Conversation

@inflop
Copy link
Copy Markdown
Owner

@inflop inflop commented Apr 28, 2026

Introduce CalculateNetAndDiscount and CalculateGrossAndNetDiscount
on InvoiceLineItem to compute both values in a single pass, avoiding
a redundant second invocation of TotalNetWith / TotalGrossWith.

All three calculation strategies now use these combined methods.
Remove the default Calculate(lineItems, rounding) overload from
IVatCalculationStrategy — callers must provide explicit discount behavior.

Also:

  • Change Quantity.One from a computed property to a static readonly field to avoid unnecessary allocations
  • Multi-target test project: net8.0;net9.0;net10.0

 Introduce CalculateNetAndDiscount and CalculateGrossAndNetDiscount
 on InvoiceLineItem to compute both values in a single pass, avoiding
 a redundant second invocation of TotalNetWith / TotalGrossWith.

 All three calculation strategies now use these combined methods.
 Remove the default Calculate(lineItems, rounding) overload from
 IVatCalculationStrategy — callers must provide explicit discount behavior.

 Also:
 - Change Quantity.One from a computed property to a static readonly
   field to avoid unnecessary allocations
 - Multi-target test project: net8.0;net9.0;net10.0

Co-authored-by: Copilot <copilot@github.com>
Copilot AI review requested due to automatic review settings April 28, 2026 18:00
@inflop inflop merged commit 7ecd7ce into master Apr 28, 2026
3 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors VAT line-item calculations to compute net/gross and net-equivalent discounts in a single pass, reducing duplicate work across calculation strategies while also tightening strategy API usage and broadening test TFMs.

Changes:

  • Add combined InvoiceLineItem helpers for net+discount and gross+net-discount calculations, and update all strategies to use them.
  • Remove the default IVatCalculationStrategy.Calculate(lineItems, rounding) overload to require explicit discount behavior.
  • Multi-target the test project (net8.0;net9.0;net10.0) and change Quantity.One implementation to avoid repeated allocations.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/Inflop.VatSharp.Tests/Inflop.VatSharp.Tests.csproj Multi-target test project across net8/net9/net10.
src/Inflop.VatSharp/ValueObjects/Quantity.cs Refactor Quantity.One from computed member to cached instance.
src/Inflop.VatSharp/ValueObjects/InvoiceLineItem.cs Add combined calculation helpers and switch Calculate to use them.
src/Inflop.VatSharp/Strategies/Calculation/SumOfLineItemVatAmountsStrategy.cs Use combined net+discount helper per item.
src/Inflop.VatSharp/Strategies/Calculation/IVatCalculationStrategy.cs Remove default overload that implied a discount behavior.
src/Inflop.VatSharp/Strategies/Calculation/FromSumOfNetValuesStrategy.cs Use combined net+discount helper inside grouping loop.
src/Inflop.VatSharp/Strategies/Calculation/FromSumOfGrossValuesStrategy.cs Use combined gross+net-discount helper inside grouping loop.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 30 to +31
/// <summary>A quantity of exactly one.</summary>
public static Quantity One => new(1m);
public static readonly Quantity One = Of(1);
Comment on lines +111 to +112
/// avoiding a redundant second invocation of <see cref="TotalGrossWith"/> via
/// <see cref="DiscountAmountNetWith"/>.
Comment on lines +53 to 55
var (itemGross, itemDiscount) = item.CalculateGrossAndNetDiscount(discountBehavior, rounding);

sumGross += itemGross;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants